home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / For your think c folder / VA Kit ƒ / VAClip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-02  |  4.0 KB  |  221 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: VAClip.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Monday, November 2, 1992, 16:52
  6.      Created: Friday, March 20, 1987, 17:24
  7.  
  8.      Copyright © 1987-1992, Juri Munkki
  9. /*/
  10.  
  11. #include "VAInternal.h"
  12. #include "VA.h"
  13.  
  14. /*
  15. **    This is a total rewrite of the old clipping
  16. **    routine. The old routine passed some invisible
  17. **    lines as visible and caused nasty crashes in
  18. **    some applications. The old version was safe to
  19. **    use with STORM, but failed when used with a
  20. **    more demanding application.
  21. **
  22. **    The rectangle pointed to by rp is clipping to
  23. **    the VA.frame boundaries. The routine returns
  24. **    TRUE, if the resulting line is visible.
  25. */
  26. int        VAClip(
  27.     Rect    *rp)
  28. {
  29. asm    {    movem.l    D3-D7,-(sp)
  30.         move.l    rp,A0
  31.         
  32.         move.w    Rect.left(A0),D0
  33.         move.w    Rect.right(A0),D1
  34.         move.w    Rect.top(A0),D2
  35.         move.w    Rect.bottom(A0),D3
  36.         
  37.         move.w    VA.frame.left,D4
  38.         cmp.w    D4,D0
  39.         bge        @leftx1ok
  40.         cmp.w    D4,D1
  41.         blt        @reject
  42. @leftx1ok
  43.         move.w    VA.frame.right,D5
  44.         cmp.w    D5,D0
  45.         blt        @rightx1ok
  46.         cmp.w    D5,D1
  47.         bge        @reject
  48. @rightx1ok
  49.         move.w    VA.frame.top,D6
  50.         cmp.w    D6,D2
  51.         bge        @topy1ok
  52.         cmp.w    D6,D3
  53.         blt        @reject
  54. @topy1ok
  55.         move.w    VA.frame.bottom,D7
  56.         cmp.w    D7,D2
  57.         blt        @bottomy1ok
  58.         cmp.w    D7,D3
  59.         bge        @reject
  60. @bottomy1ok
  61.         
  62.         cmp.w    D4,D0
  63.         bge.s    @x1leftdone
  64.         move.w    D4,Rect.left(A0)
  65.         sub.w    D0,D4                ; D4 = leftclip - x1
  66.         sub.w    D1,D0                ; D0 = x1 - x2
  67.         sub.w    D2,D3                ; D3 = y2 - y1
  68.         muls.w    D4,D3                ; D3 = dy * t
  69.         divs.w    D0,D3                ; D3 = (dy * t)/-dx
  70.         sub.w    D3,D2                ; D2 = y1 - D3
  71.         move.w    D2,Rect.top(A0)
  72.         move.w    VA.frame.left,D4
  73.  
  74.         move.w    Rect.left(A0),D0
  75.         move.w    Rect.right(A0),D1
  76.         move.w    Rect.bottom(A0),D3
  77. @x1leftdone
  78.         cmp.w    D4,D1
  79.         bge.s    @x2leftdone
  80.         move.w    D4,Rect.right(A0)
  81.         sub.w    D1,D4                ; Same algorithm as in above
  82.         sub.w    D0,D1
  83.         sub.w    D3,D2
  84.         muls.w    D4,D2
  85.         divs.w    D1,D2
  86.         sub.w    D2,D3
  87.         move.w    D3,Rect.bottom(A0)
  88.         
  89.         move.w    Rect.left(A0),D0
  90.         move.w    Rect.right(A0),D1
  91.         move.w    Rect.top(A0),D2
  92. @x2leftdone
  93.         cmp.w    D5,D0
  94.         blt.s    @x1rightdone
  95.         move.w    D5,D4
  96.         subq.w    #1,D4
  97.         move.w    D4,Rect.left(A0)
  98.         sub.w    D0,D4
  99.         sub.w    D1,D0
  100.         sub.w    D2,D3
  101.         muls.w    D4,D3
  102.         divs.w    D0,D3
  103.         sub.w    D3,D2
  104.         move.w    D2,Rect.top(A0)
  105.  
  106.         move.w    Rect.left(A0),D0
  107.         move.w    Rect.right(A0),D1
  108.         move.w    Rect.bottom(A0),D3
  109. @x1rightdone
  110.         cmp.w    D5,D1
  111.         blt.s    @x2rightdone
  112.         subq.w    #1,D5
  113.         move.w    D5,Rect.right(A0)
  114.         sub.w    D1,D5
  115.         sub.w    D0,D1
  116.         sub.w    D3,D2
  117.         muls.w    D5,D2
  118.         divs.w    D1,D2
  119.         sub.w    D2,D3
  120.         move.w    D3,Rect.bottom(A0)
  121.  
  122.         move.w    Rect.left(A0),D0
  123.         move.w    Rect.right(A0),D1
  124.         move.w    Rect.top(A0),D2
  125. @x2rightdone
  126.         cmp.w    D6,D2
  127.         bge        @topstillok
  128.         cmp.w    D6,D3
  129.         blt        @reject
  130. @topstillok
  131.         cmp.w    D7,D2
  132.         blt        @bottomstillok
  133.         cmp.w    D7,D3
  134.         bge        @reject
  135. @bottomstillok
  136.  
  137.         cmp.w    D6,D2
  138.         bge.s    @y1topdone
  139.         move.w    D6,Rect.top(A0)
  140.         move.w    D6,D4
  141.         sub.w    D2,D4
  142.         sub.w    D3,D2
  143.         sub.w    D0,D1
  144.         muls.w    D4,D1
  145.         divs.w    D2,D1
  146.         sub.w    D1,D0
  147.         move.w    D0,Rect.left(A0)
  148.  
  149.         move.w    Rect.right(A0),D1
  150.         move.w    Rect.top(A0),D2
  151.         move.w    Rect.bottom(A0),D3
  152. @y1topdone
  153.         cmp.w    D6,D3
  154.         bge.s    @y2topdone
  155.         move.w    D6,Rect.bottom(A0)
  156.         move.w    D6,D4
  157.         sub.w    D3,D4
  158.         sub.w    D2,D3
  159.         sub.w    D1,D0
  160.         muls.w    D4,D0
  161.         divs.w    D3,D0
  162.         sub.w    D0,D1
  163.         move.w    D1,Rect.right(A0)
  164.         
  165.         move.w    Rect.left(A0),D0
  166.         move.w    Rect.top(A0),D2
  167.         move.w    Rect.bottom(A0),D3
  168. @y2topdone
  169.         cmp.w    D7,D2
  170.         blt.s    @y1bottomdone
  171.         move.w    D7,D4
  172.         subq.w    #1,D4
  173.         move.w    D4,Rect.top(A0)
  174.         sub.w    D2,D4
  175.         sub.w    D3,D2
  176.         sub.w    D0,D1
  177.         muls.w    D4,D1
  178.         divs.w    D2,D1
  179.         sub.w    D1,D0
  180.         move.w    D0,Rect.left(A0)
  181.  
  182.         move.w    Rect.right(A0),D1
  183.         move.w    Rect.top(A0),D2
  184.         move.w    Rect.bottom(A0),D3
  185.  
  186. @y1bottomdone
  187.         cmp.w    D7,D3
  188.         blt.s    @y2bottomdone
  189.         subq.w    #1,D7
  190.         move.w    D7,Rect.bottom(A0)
  191.         sub.w    D3,D7
  192.         sub.w    D2,D3
  193.         sub.w    D1,D0
  194.         muls.w    D7,D0
  195.         divs.w    D3,D0
  196.         sub.w    D0,D1
  197.         move.w    D1,Rect.right(A0)
  198.         move.w    Rect.left(A0),D0
  199. @y2bottomdone
  200.         move.w    VA.frame.left,D4
  201.         cmp.w    D4,D0
  202.         bge        @leftstillok
  203.         cmp.w    D4,D1
  204.         blt        @reject
  205. @leftstillok
  206.         move.w    VA.frame.right,D5
  207.         cmp.w    D5,D1
  208.         blt        @rightstillok
  209.         cmp.w    D5,D1
  210.         bge        @reject
  211. @rightstillok
  212.  
  213.         moveq.l    #1,D0
  214.         bra.s    @alldone
  215.         
  216. @reject
  217.         moveq.l    #0,D0
  218. @alldone
  219.         movem.l    (sp)+,D3-D7
  220.     }
  221. }